<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <title>tracking.js - face alignment with images</title>
  <link rel="stylesheet" href="assets/demo.css">

  <script src="../node_modules/tracking/build/tracking-min.js"></script>
  <script src="./face.js"></script>

  <style>
    .rect,
    .circle {
      left: -1000px;
      position: absolute;
      top: -1000px;
    }

    .rect {
      border: 2px solid #a64ceb;
    }

    .circle {
      border-radius: 50%;
      box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.3);
    }

    #img {
      position: absolute;
      top: 50%;
      left: 50%;
      margin: -200px 0 0 -200px;
    }
  </style>
</head>

<body>
  <div class="demo-title">
    <p><a href="http://trackingjs.com" target="_parent">tracking.js</a> － align face landmarks to images</p>
  </div>

  <div class="demo-frame">
    <div class="demo-container">
      <img id="img" src="assets/faces.jpg" />
      <div id="photo"></div>
    </div>
  </div>

  <script>
  window.onload = function() {
 var img = document.getElementById('img');
 var tracker = new tracking.ObjectTracker('face');
 tracking.track(img, tracker);
 tracker.on('track', function(event) {
 event.data.forEach(function(rect) {
 console.log(rect.x, rect.y, rect.width, rect.height);
 plotRectangle(rect.x, rect.y, rect.width, rect.height);
 });
 });
 // 下方的代码可以先忽略

 var plotRectangle = function(x, y, w, h) {
 var rect = document.createElement('div');
 var arrow = document.createElement('div');
 var input = document.createElement('input');
 input.value = friends.pop();
 rect.onclick = function name() {
 input.select();
 };
 arrow.classList.add('arrow');
 rect.classList.add('rect');
 rect.appendChild(input);
 rect.appendChild(arrow);
 document.getElementById('photo').appendChild(rect);
 rect.style.width = w + 'px';
 rect.style.height = h + 'px';
 rect.style.left = (img.offsetLeft + x) + 'px';
 rect.style.top = (img.offsetTop + y) + 'px';
 };
};
  </script>

</body>

</html>